<template>
  <el-form :model="formData" label-width="auto" style="max-width: 600px">
    <el-form-item label="店铺名称">
      <el-input v-model="formData.name" placeholder="请输入店铺名称"/>
    </el-form-item>
    <el-form-item label="店铺类型">
      <el-input v-model="formData.storeType" placeholder="请输入店铺类型" />
    </el-form-item>
    <el-form-item label="起送费">
      <el-input v-model="formData.price1" placeholder="请输入起送费" />
    </el-form-item>
    <el-form-item label="配送费">
      <el-input v-model="formData.price2" placeholder="请输入配送费"  />
    </el-form-item>
    <el-form-item>
      <el-button align="center" type="primary" @click="onSubmit">提交</el-button>
      <el-button align="center" @click="cancel">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
import {ref, defineProps, defineEmits, onMounted,watch } from "vue";
import requestUtil from "@/api/request.js";
import { ElMessage } from "element-plus";

// do not use same name with ref
const props = defineProps({
  storeId: {
    type: Number,
    required: true
  }
});
let formData = ref({})
let storeId = ref(0)
storeId.value = props.storeId
const getUserInfo = async () => {
  console.log(storeId.value);
  
  let res = await requestUtil.get("management/getStoreInfo?storeId=" + storeId.value);
  formData.value = res.data.storeInfo;
}
onMounted(() => {
  getUserInfo();
})


const emits = defineEmits(["cancel", "submit"]);
const cancel = () => {
  emits("cancel");
};
const onSubmit = async () => {
  let res = await requestUtil.put("management/updateStoreInfo/",{storeId: storeId.value, storeInfo: formData.value});
  if (res.data.code === 200) {
    ElMessage.success("修改成功");
    emits("submit");
  }
  
};
</script>